unit DataPersistentsUnit;

interface

uses
  SysUtils, DBClient, MConnect, IDataPersistentsUnit, CardServer_TLB;


type
  TDataPersistent = class(TInterfacedObject, IDLLDataPersistent)
  private
    pIRDMDataPerDisp: IRDMCardServerDisp;
  protected
    procedure SetIDataPerDisp(tmpDisp: IRDMCardServerDisp); safecall;
    function GetIDataPerDisp: IRDMCardServerDisp; safecall;

    function BeginTrans(out pMsg: WideString): Boolean; safecall;
    function CommitTrans(out pMsg: WideString): Boolean; safecall;
    function RollBackTrans(out pMsg: WideString): Boolean; safecall;
    function SelectData(const PWStr: pWideString; var pPrvName: WideString): Boolean; stdcall;
    function InsertDataSet(const PWStr: pWideString; out pMsg: WideString): Boolean; stdcall;
    function UpdateDataSet(const PWStr: pWideString; out pMsg: WideString): Boolean; stdcall;
    function DeleteDataSet(const PWStr: pWideString; out pMsg: WideString): Boolean; stdcall;
    function CloseDataSet(const PWStr: pWideString): Integer; stdcall;
    procedure AddUser(const ip: WideString; const host: WideString; const uname: WideString;
      const time: WideString; const state: WideString); safecall;
    procedure DelUser(const ip: WideString; const host: WideString; const uname: WideString;
      const time: WideString; const state: WideString); safecall;
    procedure bo_GetVoList(const sBoSrvObj: WideString; const sBOSrvName: WideString;
      out pVOlist: OleVariant); safecall;

  private
    function ExecuteDataSet(const PWStr: pWideString; out pMsg: WideString): Boolean; stdcall;

  public
    property IRDMDataPerDisp: IRDMCardServerDisp read GetIDataPerDisp write SetIDataPerDisp;
    constructor Create;
  end;

implementation

constructor TDataPersistent.Create;
begin
  inherited Create;
end;

function TDataPersistent.GetIDataPerDisp: IRDMCardServerDisp; safecall;
begin
  Result := pIRDMDataPerDisp;
end;

procedure TDataPersistent.SetIDataPerDisp(tmpDisp: IRDMCardServerDisp); safecall;
begin
  pIRDMDataPerDisp := tmpDisp;
end;

function TDataPersistent.BeginTrans(out pMsg: WideString): Boolean; safecall;
var
  wsRes: WideString;
begin
  Result := false;

  try
    pIRDMDataPerDisp.BeginTrans(wsRes, pMsg);
    if wsRes = '1' then
      Result := true
    else
      Result := false;
  except
    Result := false;
  end;
end;

function TDataPersistent.CommitTrans(out pMsg: WideString): Boolean; safecall;
var
  wsRes: WideString;
begin
  Result := false;

  try
    pIRDMDataPerDisp.CommitTrans(wsRes, pMsg);
    if wsRes = '1' then
      Result := true
    else
      Result := false;
  except
    Result := false;
  end;
end;

function TDataPersistent.RollBackTrans(out pMsg: WideString): Boolean; safecall;
var
  wsRes: WideString;
begin
  Result := false;

  try
    pIRDMDataPerDisp.RollBackTrans(wsRes, pMsg);
    if wsRes = '1' then
      Result := true
    else
      Result := false;
  except
    Result := false;
  end;
end;

function TDataPersistent.SelectData(const PWStr: pWideString; var pPrvName: WideString): Boolean; stdcall;
var
  sSqlStr: WideString;
  sPrvName: WideString;
begin
  Result := True;
  sSqlStr := PWStr^;
  sPrvName := pPrvName;

  try
    pIRDMDataPerDisp.SelectData(sSqlStr, sPrvName);

    if (length(Trim(sPrvName)) = 0) or (Pos('DSP', UpperCase(sPrvName)) <= 0) then
    begin
      Result := False;
      Exit;
    end;

    pPrvName := sPrvName;
    Result := true;
  except
    Result := False;
  end;
end;


procedure TDataPersistent.AddUser(const ip: WideString; const host: WideString; const uname: WideString;
  const time: WideString; const state: WideString); safecall;
begin
  pIRDMDataPerDisp.AddUser(ip, host, uname, time, state);
end;

procedure TDataPersistent.DelUser(const ip: WideString; const host: WideString; const uname: WideString;
  const time: WideString; const state: WideString); safecall;
begin
  pIRDMDataPerDisp.DelUser(ip, host, uname, time, state);
end;

procedure TDataPersistent.bo_GetVoList(const sBoSrvObj: WideString; const sBOSrvName: WideString;
  out pVOlist: OleVariant);
begin
  pIRDMDataPerDisp.bo_GetVoList(sBoSrvObj, sBOSrvName, pVOlist);
end;

function TDataPersistent.ExecuteDataSet(const PWStr: pWideString; out pMsg: WideString):
  Boolean; stdcall;
var
  i_Result: OleVariant;
  sSqlStr, wsRes: WideString;
begin
  Result := false;
  sSqlStr := PWStr^;

  try
    pIRDMDataPerDisp.ExecuteData(sSqlStr, wsRes, pMsg);
    if wsRes = '1' then
      Result := true
    else
      Result := false;
  except
    Result := false;
  end;
end;

function TDataPersistent.InsertDataSet(const PWStr: pWideString; out pMsg: WideString):
  Boolean; stdcall;
begin
  Result := ExecuteDataSet(PWStr, pMsg);
end;

function TDataPersistent.UpdateDataSet(const PWStr: pWideString; out pMsg: WideString):
  Boolean; stdcall;
begin
  Result := ExecuteDataSet(PWStr, pMsg);
end;

function TDataPersistent.DeleteDataSet(const PWStr: pWideString; out pMsg: WideString):
  Boolean; stdcall;
begin
  Result := ExecuteDataSet(PWStr, pMsg);
end;

function TDataPersistent.CloseDataSet(const PWStr: pWideString): Integer; stdcall;
var
  sSqlStr: WideString;
begin
  Result := -1;
  sSqlStr := PWStr^;

  try
    pIRDMDataPerDisp.CloseDataSet(sSqlStr);
    Result := 0;
  except
    Result := -1;
  end;
end;

end.
